###############################################################################
# Author: PythonXadds>
#   #Date: Monday 1st September 2020
#
#
# This file controls behavior of twm window manager. Although twm is pretty old
# it is stull usefull on slow remote display. Basicaly it is verry stupid one 
# but it has a powerful configuration options and can look pretty well
#
# Note: I created this rc for use with weirdx xserver which is a little buggy..
#       so i put f.refresh in "move-to-raise" function which is save to remove
#       when twm is used with another xserver
###############################################################################
# These parameters defines twm look

# These control various workspace colors.
Color {
	BorderColor		"gray85"
	BorderTileBackground	"black"
	BorderTileForeground	"gray85"
	DefaultBackground	"black"
	DefaultForeground	"gray85"
	IconBackground		"black"
	IconForeground		"gray85"
	IconBorderColor		"gray85"
	IconManagerBackground	"black"
	IconManagerForeground	"gray85"
	IconManagerHighlight	"red"
	MenuBackground		"black"
	MenuForeground		"gray85"
	MenuShadowColor		"gray85"
	MenuTitleBackground	"black"
	MenuTitleForeground	"gray85"
	TitleBackground		"black"
	TitleForeground		"gray85"
}

# Controls shape of cursor under various conditions.
Cursors {
	Frame			"top_left_arrow"
	Title			"top_left_arrow"
	Icon			"top_left_arrow"
	IconMgr			"top_left_arrow"
	Move			"fleur"
	Resize			"sizing"
	Menu			"sb_right_arrow"
	Button			"hand1"
	Wait			"watch"
	Select			"dot"
	Destroy			"pirate"
}

# Various font definitions
TitleFont "-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*"
ResizeFont "-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*"
MenuFont "-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*"
IconFont "-adobe-helvetica-bold-r-normal--*-100-*-*-*-*-*-*"
IconManagerFont "-adobe-helvetica-bold-r-normal--*-100-*-*-*"
IconFont			"variable"
IconManagerFont		"variable"
MenuFont			"variable"
TitleFont			"variable"

# Pixel width of border around windows.
BorderWidth			1

# Sets space between title bar and application window.
#FramePadding			2

# Size of border around desktop icons.
IconBorderWidth		1

# Desktop-style icons will be put in the following screen region. (we use IconManger instead)
#IconRegion			"72x600-0+0" NORTH EAST 72 72

# Initial location of Icon Manager, colums of icons.
IconManagerGeometry		"90-0+30" 1

# This makes sure child windows have a border and title bar.
##DecorateTransients

# This makes title bars as wide as the window. (is this working?)
##DontSqueezeTitle

# Don't create Icon Manager (stupid!)
##NoIconManagers

# Keeps menus from having shadows behind them. (stupid!;)
##NoMenuShadows

# This makes title bars short, like a tab on a file folder. (ugly!)
##SqueezeTitle



###############################################################################
# These parameters controls twm and windows behaviour

# Length of time to achieve a "double-click" for constained move.
ConstrainedMoveTime		400

# Windows resize without having to drag pointer over their borders.
AutoRelativeResize

# This disallows moving windows off the visible screen.
DontMoveOff

IconDirectory "~/.twm/ico"
# RightTitleButton "menu0" = f.identify
RightTitleButton "window_max" = f.fullzoom
RightTitleButton "delete11" = f.delete
#RightTitleButton "resize11" = f.resize

# Set Named Windows Titles
# Named Windows will have no title bar.
NoTitle				{ "TWM Icon Manager" "xclock" }

# Force named windows to have title bars.
#MakeTitle			{}

# Windows are automatically placed; no need to drag out outline.
RandomPlacement

# Windows are not automatically brought to top when deinconified.
##NoRaiseonDeiconify

# Windows are not automatically brought to top when moved.
##NoRaiseOnMove

# Windows are not automatically brought to top when resized.
##NoRaiseOnResize

# Windows are not automatically brought to top when cursor warps to them.
##NoRaiseOnWarp

# Show windows contents while draggin'
#OpaqueMove

# Move cursor into windows when they're deiconified.
WarpCursor


##############################################################################
# Set IconManager behaviour

# Display Icon Manager on startup.
ShowIconManager

# Sort icons in Icon Manager in alphabetical order.
SortIconManager

# Named windows will not be shown in Icon Manager
IconManagerDontShow		{ "xclock" "Virtual Desktop" }

# Named windows will _not_ go to icon manager, but will have desktop icons.
#DontIconifyByUnmapping		{ "xclock" "Virtual Desktop" }

# Makes applications use icons in Icons directive, instead of their own.
#ForceIcons

# Iconifying a window sends it to the Icon Manager
IconifyByUnmapping

# Named windows will be shown in Icon Manager
#IconManagerShow

# You can specify that certain apps have icons other than the default.
#Icons				{}

# Named windows will start iconized.
#StartIconified			{}

# Disable default titles and buttons .. so we should provide bindings - too pitty
NoDefaults

# Dont loose focus when mouse moves away from it (this is annoying)
#NoTitleFocus

# Makes an extra button on each title bar, that calls up menu below.
LeftTitleButton  "menu12"	= f.menu "WindowOpsMenu"

RightTitleButton "gray"		= f.iconify
RightTitleButton "dropbar8"	= f.fullzoom
RightTitleButton "dot"		= f.delete

# Clicking on the desktop brings up the system-wide menu.
Function "move-or-raise" { f.move f.deltastop f.raise f.refresh }
Button1 =  : root : f.menu "DesktopMenuApps"
Button2 =  : root : f.exec "xrefresh"
Button3 =  : root : f.menu "DesktopMenuTools"

Button1 =  : title : f.function "move-or-raise"
Button3 =  : title : f.menu "WindowOpsMenu"

Button1 =  : iconmgr : f.iconify
Button3 =  : iconmgr : f.menu "WindowOpsMenu"

##############################################################################
# Declare some usefull menus

Menu "WindowOpsMenu" {
	"Iconify"		f.iconify
	"Move .."		f.move
	"Resize..."		f.resize
	"Zoom"			f.fullzoom
	"Refresh"		f.winrefresh
	""			f.nop
	"Close"			f.delete
	"Kill"			f.destroy
}

Menu "DesktopMenuApps" {
	"Applications"		f.title
	"SetBg"			f.exec "xsetroot -solid 'rgb:2/a/9'"
	"Clock"			f.exec "xclock -bg 'rgb:2/a/9' -fg black -digital -geometry '-0-0' -padding 0 &"
	""			f.nop
	"Xterm"			f.exec "xterm -ls -bg black -fg gray85 &"
	"Terminal"			f.exec "xfce4-terminal &"
	"Sublime"           f.exec "sublime-text &"
    "Google chrome"     f.exec "google-chrome &"
    "Double commander"  f.exec "doublecmd &"
    "Command" f.exec "xterm -geometry 25x1+840+1150 -title Run -e ~/.twm/scripts/getrun &"
        ""			f.nop
	"Restart"		f.restart
	"Exit"			f.quit
}

Menu "DesktopMenuTools" {
	"Tools"			f.title
	"Iconify"		f.iconify
	"Maximize"		f.fullzoom
	"Move ..."		f.move
	"Resize ..."		f.resize
	"Refresh"		f.winrefresh
	""			f.nop
	"Kill"			f.destroy
	"Close"			f.delete
}

# Virtual Desktops

function "desktop-1" {
	f.exec "xmessage -center -timeout 1 -buttons OK DESKTOP NO: 1 &"
	f.exec "vdesk 1"
	}
	function "desktop-2" {
	f.exec "xmessage -center -timeout 1 -buttons OK DESKTOP NO: 2 &"
	f.exec "vdesk 2" 
	}
	function "desktop-3" {
	f.exec "xmessage -center -timeout 1 -buttons OK DESKTOP NO: 3 &"
	f.exec "vdesk 3" 
	}
	function "desktop-4" {
	f.exec "xmessage -center -timeout 1 -buttons OK DESKTOP NO: 4 &"
	f.exec "vdesk 4"
	}

	"1" = c : all : f.function "desktop-1"
	"2" = c : all : f.function "desktop-2"
	"3" = c : all : f.function "desktop-3"
	"4" = c : all : f.function "desktop-4"

function "next" {
	f.exec "A=$((`vdesk`+1)); if [ $A = 5 ] ; then A=1 ; fi ; vdesk $A"
	f.exec "B=$((`vdesk`)); xmessage -center -timeout 1 -buttons OK DESKTOP NO: $B &"
	}

	function "prev" {
	f.exec "A=$((`vdesk`-1)); if [ $A = 0 ] ; then A=4 ; fi ; vdesk $A"
	f.exec "B=$((`vdesk`)); xmessage -center -timeout 1 -buttons OK DESKTOP NO: $B &"
	}
	"Right" = c : all : f.function "next"
	"Left"  = c : all : f.function "prev"
	
	


# Sinmenu "WindowMenu" {
	"Sendto 1"   f.exec "/home/orby/.twm/scripts/sendto-1 &"
	"Sendto 2"   f.exec "/home/orby/.twm/scripts/sendto-2 &"
	"Sendto 3"   f.exec "/home/orby/.twm/scripts/sendto-3 &"
	"Sendto 4"   f.exec "/home/orby/.twm/scripts/sendto-4 &"
	}
	
#	since twm cannot autostart applications I created this script. 
# It will set desktop foreground to default twm menu background color and
# will start xcloc on bottom down corner of the screen.
# --- cut here ---
# !/bin/sh
# echo Starting twm window manager ...
# twm &
# xsetroot -solid 'rgb:2/a/9'
# xclock -bg 'rgb:2/a/9' -fg black -digital -geometry '-0-0' -padding 0 &
# exec xterm
# --- cut here ---

# xsetroot -bitmap bricks.xbm -fg "#808080" -bg "#101010"
